﻿using System;
using System.Collections.Generic;
using System.Text;
using Silmoon;
using System.IO;

namespace interpreter_base.Functions
{
    class BaseOperators
    {
        public BaseOperators(string s)
        {

        }
        public static void Say(Compiler compiler, string[] spaceSplitArray)
        {
            Console.WriteLine(compiler.cEnv.GetValue(spaceSplitArray[1]));
        }
        public static void Prt(Compiler compiler, string[] spaceSplitArray)
        {
            Console.Write(compiler.cEnv.GetValue(spaceSplitArray[1]));
        }
        public static void def(Compiler compiler, string[] spaceSplitArray)
        {
            if (spaceSplitArray[2] == "=")
            {
                compiler.cEnv.Variables[spaceSplitArray[1]] = compiler.cEnv.GetValue(spaceSplitArray[3]);
                //compiler.cEnv.Variables.Add(spaceSplitArray[1], compiler.cEnv.GetValue(spaceSplitArray[3]));
            }
        }

        public static void Clr(Compiler compiler, string[] spaceSplitArray)
        {
            compiler.cEnv.Variables.Clear();
        }
        public static void Set(Compiler compiler, string[] spaceSplitArray, string line)
        {
            switch (SmString.FormArrayGetString(spaceSplitArray, 1))
            {
                case "errorresume":
                    if (SmString.StringToBool(SmString.FormArrayGetString(spaceSplitArray, 2)))
                        compiler.cEnv._Error_Resume = true;
                    else compiler.cEnv._Error_Resume = false;
                    break;
                case "nowaring":
                    if (SmString.StringToBool(SmString.FormArrayGetString(spaceSplitArray, 2)))
                        compiler.cEnv._NoWaring = true;
                    else compiler.cEnv._NoWaring = false;
                    break;
                default:
                    compiler.onCompileUnknownScriptLine(line, spaceSplitArray);
                    break;
            }
        }
        public static void exec(Compiler compiler, string[] spaceSplitArray)
        {
            string[] line = File.ReadAllLines(compiler.cEnv.GetValue(spaceSplitArray[1]));
            compiler.Compile(line);
        }
    }
}
